﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UWarrantyCardVipList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "UWarrantyCardVipList";
            }
        }
        #region 属性 (查询条件)


        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");

            }
        }
        protected string CustomerName
        {
            get
            {
                return GetRequestValue<string>("CustomerName", "");

            }
        }
        protected string CustomerIDCard
        {
            get
            {
                return GetRequestValue<string>("CustomerIDCard", "");

            }
        }

        protected string AgentName
        {
            get
            {
                return GetRequestValue<string>("AgentName", "");

            }
        }
        protected string Birthday
        {
            get
            {
                return GetRequestValue<string>("Birthday", "");

            }
        }
        protected string AgentAddress
        {
            get
            {
                return GetRequestValue<string>("AgentAddress", "");

            }
        }


        #endregion
        protected override string orderField
        {
            get
            {
                return GetRequestValue<string>("orderfield", "IntoDate");
            }
        }

        protected override string orderDirection
        {
            get
            {
                return GetRequestValue<string>("orderDirection", "desc");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }

        protected string GetSQLWhere()
        {

            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(SerialNumber))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("SerialNumber", QueryOperatorsEnum.包含, SerialNumber);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(CustomerName))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("CustomerName", QueryOperatorsEnum.包含, CustomerName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(CustomerIDCard))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("CustomerIDCard", QueryOperatorsEnum.包含, CustomerIDCard);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(AgentName))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("AgentName", QueryOperatorsEnum.包含, AgentName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(Birthday))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("Birthday", QueryOperatorsEnum.等于, Birthday);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (!string.IsNullOrEmpty(AgentAddress))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("AgentAddress", QueryOperatorsEnum.包含, AgentAddress);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }
            if (true)
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator("isvip", QueryOperatorsEnum.等于, "1");
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlcommonFiled;
                }
                else
                {
                    wheresql = sqlcommonFiled;
                }
            }


          

            return wheresql;
        }

        protected DataTable sumdt = new DataTable();
        protected void DataBind()
        {
            //  string wheresql = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);
            DataTableCollection dts = UWarrantyCardController.GetPagination(GetSQLWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataSource = dts[0];
            this.rpMenu.DataBind();
            sumdt = dts[1];
        }

        protected object GetSUMDT(string FiledName)
        {
            if (sumdt.Rows.Count <= 0)
                return 0;
            return sumdt.Rows[0][FiledName];
        }
    }
}